<template>
  <div class="exam-detail">
    <van-notice-bar
      color="#1989fa"
      wrapable
      :scrollable="false"
      background="#ecf9ff"
      left-icon="info-o"
    >
      <div class="xxl">握力评估测试/SARC测试二选一</div>
    </van-notice-bar>
    <van-collapse v-model="activeName" accordion>
      <van-collapse-item size="large" title="握力评估" :name="3">
        <van-notice-bar wrapable>
          <div class="xxl">
            请您站立，手握弹簧，伸直肘部，手臂自然下垂，用尽全力握紧开始测量。请您至少进行两次测量，精确至0.1千克，以最大数字测量结果为准。
          </div>
        </van-notice-bar>
        <van-cell size="large" title="性别">
          <!-- 使用 title 插槽来自定义标题 -->
          <template #right-icon>
            <van-radio-group v-model="quest[0]" direction="horizontal">
              <van-radio name="1">男</van-radio>
              <van-radio name="2">女</van-radio>
            </van-radio-group>
          </template>
        </van-cell>
        <van-field
          v-model="quest[1]"
          size="large"
          type="number"
          label="握力"
          placeholder="请输入握力"
        />
      </van-collapse-item>
      <van-collapse-item size="large" title="5次起坐试验" :name="4">
        <van-notice-bar wrapable>
          受试者坐在无扶手椅子上，双腿着地，背部不贴靠椅，背上双手交叉于胸前测。计时人员说“准备，开始”后立即计时。受试者听到指令以最快的速度完成5次起立和坐下的动作。请注意：受试者起立时膝关节完全伸直。如果受试者在重复站立过程中出现以下几种情况则终止试验,该项试验未通过：①无法坚持；②呼吸短促；③挥手摆动以调节平衡。
        </van-notice-bar>
        <van-field
          v-model="quest[0]"
          type="number"
          label="平均用时"
          placeholder="请输入起坐平均用时"
        />
      </van-collapse-item>
    </van-collapse>
  </div>
</template>

<script>
import { Button, Icon, NoticeBar, Cell, RadioGroup, Radio, Field } from "vant";
import { mapGetters } from "vuex";
import Taro from "@tarojs/taro";
import { Collapse, CollapseItem } from "vant";
export default {
  components: {
    [Radio.name]: Radio,
    [RadioGroup.name]: RadioGroup,
    [Cell.name]: Cell,
    [NoticeBar.name]: NoticeBar,
    [Collapse.name]: Collapse,
    [CollapseItem.name]: CollapseItem,
    [Button.name]: Button,
    [Icon.name]: Icon,
    [Field.name]: Field
  },
  data() {
    return {
      questions: [],
      quest: [],
      answer: "",
      activeName: 3,
      form: {
        time: "",
        power: "",
        sex: "",
        exam: {},
        detailList: []
      }
    };
  },
  watch: {
    activeName(val) {
      if (val) {
        this.quest = [];
      }
    }
  },
  computed: {
    ...mapGetters(["exam"]),
    total() {
      return this.questions.length;
    },

    question() {
      return this.questions[this.index - 1] || {};
    }
  },
  onLoad(options) {
    this.setExam();
    this.getDetail(options.id);
  },
  methods: {
    setAnswer() {
      if (this.activeName == 3) {
        if (this.quest.length < 2) {
          Taro.showToast({
            title: "请回答握力评估测试所有问题",
            icon: "none"
          });
          return false;
        }
      } else {
        if (this.quest.length < 1) {
          Taro.showToast({
            title: "请回答5次起坐试验测试所有问题",
            icon: "none"
          });
          return false;
        }
      }
      this.$emit("handanswer", {
        type: this.activeName,
        answer: this.quest
      });
      return true;
    }
  }
};
</script>
